package com.kmist.xiakexing.view;

import android.content.Context;
import android.content.Intent;
import android.widget.EditText;
import android.widget.RadioButton;

import com.kmist.xiakexing.R;
import com.kmist.xiakexing.main.MainApplication;
import com.kmist.xiakexing.main.impl.Hero;
import com.kmist.xiakexing.presenters.PlayerPresenter;
import com.kmist.xiakexing.tools.Config;
import com.kmist.xiakexing.tools.DialogRe;
import com.kmist.xiakexing.utils.scene.PlayerBean;

public class CreatePlayerDialog extends DialogRe {

    private final EditText login_02_edit_newplayer;
    private final RadioButton login_02_radiobtn_man;
    private final RadioButton login_02_radiobtn_woman;
    private String gender = "man"; //性别
    private Hero hero;

    public CreatePlayerDialog(Context context) {
        super(context, R.layout.a_login_create_new_player);
        buttonOK("确定");
        Init();

        login_02_edit_newplayer = mWindow.findViewById(R.id.login_02_edit_newplayer);
        login_02_radiobtn_man = mWindow.findViewById(R.id.login_02_radiobtn_man);
        login_02_radiobtn_woman = mWindow.findViewById(R.id.login_02_radiobtn_woman);
        login_02_radiobtn_man.setChecked(true);
        hero = Hero.getInstance();

    }

    public void sureEvent(){
        super.sureEvent();
        PlayerPresenter playerPresenter = PlayerPresenter.getInstance();
        if(login_02_edit_newplayer.getText().toString().equals("")){
            Config.Alarm("角色名不为空");
        }else{
            //创建角色
            if(login_02_radiobtn_woman.isChecked()){
                gender = "Woman";
            }
            //创建角色
            PlayerBean playerBean = new PlayerBean();
            playerPresenter.setPlayerDefaultConfig(playerBean);
            playerBean.setUsex(gender);
            playerBean.setUname(login_02_edit_newplayer.getText().toString());
            playerBean.setSid(playerPresenter.calPlayerSid(playerBean.getUname(),"123456"));
            playerPresenter.addPlayer(playerBean);

            //hero.createPlayer(login_02_edit_newplayer.getText().toString(), gender);

            //跳转界面 其实这边应该返回登陆界面，再由登陆界面跳转，先这样吧
            Intent intent = new Intent(mContext, MainApplication.class);
            mContext.startActivity(intent);
        }
    }


}
